package com.hyz.service.repositoryManager.impl;

import com.hyz.client.AssetClient;
import com.hyz.client.LogClient;
import com.hyz.service.repositoryManager.RepositoryManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pojo.ResponseResult;
import pojo.assetInbound.AssetInbound;
import pojo.reposiroty.Repository;
import util.GetValue;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author HGD
 * @date 2022/10/2 10:02
 */
@Service
public class RepositoryManagerServiceImpl implements RepositoryManagerService {
    @Autowired
    private AssetClient assetClient;
    @Autowired
    private LogClient logClient;

    @Override
    public ResponseResult<List<AssetInbound>> getAssetInbound() {
        // TODO: 使用 SpringSecurity 获取仓库管理员d
        Long repositoryManagerId = 1L;
        List<Repository> chargeRepository = assetClient.getChargeRepository(repositoryManagerId);

        List<Long> repositoryIds = new ArrayList<>();
        for (Repository repository : chargeRepository) {
            repositoryIds.add(repository.getId());
        }
        List<AssetInbound> assetInbounds = logClient.getAssetInboundByRepositoryIds(repositoryIds);



        // TODO: 根据异常的类型给出对应的结果
        if (Objects.isNull(assetInbounds)) {
            return new ResponseResult<>(400, "失败", null);
        }
        return new ResponseResult<>(200, "成功", assetInbounds);
    }
}
